package org.dromara.hm.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hm.domain.vo.HmTodoTransferHistoryVo;
import org.dromara.hm.domain.bo.HmTodoTransferHistoryBo;
import org.dromara.hm.service.IHmTodoTransferHistoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 待办事项归属转移历史
 *
 * @author Hzy
 * @date 2025-06-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hm/todoTransferHistory")
public class HmTodoTransferHistoryController extends BaseController {

    private final IHmTodoTransferHistoryService hmTodoTransferHistoryService;

    /**
     * 查询待办事项归属转移历史列表
     */
    @SaCheckPermission("hm:todoTransferHistory:list")
    @GetMapping("/list")
    public TableDataInfo<HmTodoTransferHistoryVo> list(HmTodoTransferHistoryBo bo, PageQuery pageQuery) {
        return hmTodoTransferHistoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出待办事项归属转移历史列表
     */
    @SaCheckPermission("hm:todoTransferHistory:export")
    @Log(title = "待办事项归属转移历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HmTodoTransferHistoryBo bo, HttpServletResponse response) {
        List<HmTodoTransferHistoryVo> list = hmTodoTransferHistoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "待办事项归属转移历史", HmTodoTransferHistoryVo.class, response);
    }

    /**
     * 获取待办事项归属转移历史详细信息
     *
     * @param todoTransferHistoryId 主键
     */
    @SaCheckPermission("hm:todoTransferHistory:query")
    @GetMapping("/{todoTransferHistoryId}")
    public R<HmTodoTransferHistoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long todoTransferHistoryId) {
        return R.ok(hmTodoTransferHistoryService.queryById(todoTransferHistoryId));
    }

    /**
     * 新增待办事项归属转移历史
     */
    @SaCheckPermission("hm:todoTransferHistory:add")
    @Log(title = "待办事项归属转移历史", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmTodoTransferHistoryBo bo) {
        return toAjax(hmTodoTransferHistoryService.insertByBo(bo));
    }

    /**
     * 修改待办事项归属转移历史
     */
    @SaCheckPermission("hm:todoTransferHistory:edit")
    @Log(title = "待办事项归属转移历史", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmTodoTransferHistoryBo bo) {
        return toAjax(hmTodoTransferHistoryService.updateByBo(bo));
    }

    /**
     * 删除待办事项归属转移历史
     *
     * @param todoTransferHistoryIds 主键串
     */
    @SaCheckPermission("hm:todoTransferHistory:remove")
    @Log(title = "待办事项归属转移历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{todoTransferHistoryIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] todoTransferHistoryIds) {
        return toAjax(hmTodoTransferHistoryService.deleteWithValidByIds(List.of(todoTransferHistoryIds), true));
    }
}
